package com.sgq.config.redis;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.concurrent.TimeUnit;

/**
 * @author: 83778
 * @date: 2024-09-12 16:38
 * @desc:
 */
@Component
public class RedisService {

    @Value("${spring.redis.expire}")
    private Long expire;
    @Value("${spring.redis.prefix}")
    private String prefix;

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    //存缓存
    public void set(String key ,String value,Long timeOut){
        redisTemplate.opsForValue().set(key,value,timeOut, TimeUnit.SECONDS);
    }
    //取缓存
    public String get(String key){
        return (String) redisTemplate.opsForValue().get(key);
    }
    //清除缓存
    public void del(String key){
        redisTemplate.delete(key);
    }

    public String getPrefix() {
        return this.prefix;
    }

    public Long getExpire() {
        return this.expire;
    }
}
